package multi;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Constants {
	
	public static final int TEST_TYPE_MYSQL=1;
	public static final int TEST_TYPE_PG=2;
	public static final int TEST_TYPE_MONGO=3;
	
	public static final int TEST_TO_RUN=TEST_TYPE_MONGO;
	
	public static final boolean IS_MYSQL_TEST=false;//false means PostGres Test
	
	public static final boolean USE_STORED_PROC=false;//false means use direct query.
	public static final int NO_OF_THREADS = 1;
	public static final int NO_OF_LOOPS_PER_THREAD = 1; //Number of times a query or a stored proc is called in sequence in a thread.

	public static final double LAT=10;//10
	public static final double LON=78;//78
	public static final double SEARCH_RADIUS_MILES = 1000; // or 50
	public static final double RADIUS_DEGREE_UNITS = SEARCH_RADIUS_MILES/69; //1 unit 69 miles. 0.7246 units=50 miles. 14.5 miles=1000 miles.
	public static final double RADIUS_RADIANS = SEARCH_RADIUS_MILES/3959;  // Used by MongoDB
		
	//These are used only if IS_MYSQL_TEST is true
	public static final boolean IS_MYSQL_SPATIAL_TEST = false; // False means its Haversine Test.
	public static final String MYSQL_SPATIAL_QUERY = "call getGeoLocationsByRadius( " + LAT + ", " + LON + ", " + RADIUS_DEGREE_UNITS + ")";   
	public static final String HAVERSINE_QUERY = "call getGeoLocationsByHaversineOptimized( " + LAT + ", " + LON + ", " + RADIUS_DEGREE_UNITS + ")";  

	/* MySQL Values
	public static final String DB_URL = "jdbc:mysql://localhost:3306/test?";
	public static final String DB_CLASS = "com.mysql.jdbc.Driver";
	public static final String DB_USERNAME = "root";
	public static final String DB_PASSWD = "pass";
	 */
	
	// PostGres Values
	public static final String DB_URL = "jdbc:postgresql://localhost:5432/postgis?";
	public static final String DB_CLASS = "org.postgresql.Driver";
	public static final String DB_USERNAME = "postgres";
	public static final String DB_PASSWD = "pass";
	
	//Mongo Values
	public static final int RESULT_ROWS_LIMIT = 100000;
	
	/* NOTES:
	 * If USE_STORED_PROC=false - then findGeoLocationsDirectQuery is used.
	 * If USE_STORED_PROC=true - then findGeoLocationsWithStoredProc is used.
	 * IS_MYSQL_SPATIAL_TEST = true means MySQL Spatial Stored Procedure OR MySQL Spatial direct query is used.
	 * IS_MYSQL_SPATIAL_TEST = false means Haversine Stored Procedure OR Haversine direct query is used.
	 */
	
	//Store total time taken by all threads to execute here.
	public static long totaltimetaken=0;
	
	public static String sql;

	static {
		try {
			Class.forName(DB_CLASS);		
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static Connection getConnection() {
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWD);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	public static void closeConnection(Connection conn) {
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}
	
	synchronized public static void addTotalTime (long theTime)
	{
		totaltimetaken = totaltimetaken + theTime;
	}
	
	
}
